// packageA/pages/delivery-progress/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentStep: 2, // 当前配送进度步骤
        estimateTime: '11:30', // 预计送达时间
        riderInfo: {
            avatar: 'https://picsum.photos/200/200?random=10',
            name: '李师傅',
            phone: '13800138001'
        },
        progressInfo: [
            { time: '10:35' },
            { time: '10:50' },
            { time: '11:05' },
            { time: '11:08' }
        ],
        location: {
            longitude: 116.404,
            latitude: 39.915
        },
        markers: [{
            id: 1,
            latitude: 39.915,
            longitude: 116.404,
            iconPath: '/images/rider.png',
            width: 30,
            height: 30
        }, {
            id: 2,
            latitude: 39.910,
            longitude: 116.410,
            iconPath: '/images/destination.png',
            width: 30,
            height: 30
        }],
        polyline: [{
            points: [
                { longitude: 116.404, latitude: 39.915 },
                { longitude: 116.410, latitude: 39.910 }
            ],
            color: '#07C160',
            width: 4,
            dottedLine: false
        }]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // 实际项目中这里应该根据options.id请求接口获取配送进度
        console.log('订单ID:', options.id)

        // 模拟配送进度更新
        this.timer = setInterval(() => {
            if (this.data.currentStep < 3) {
                this.setData({
                    currentStep: this.data.currentStep + 1,
                    [`progressInfo[${this.data.currentStep}].time`]: this.getCurrentTime()
                })
            } else {
                clearInterval(this.timer)
            }
        }, 10000)
    },
    makePhoneCall() {
        wx.makePhoneCall({
            phoneNumber: this.data.riderInfo.phone
        })
    },

    getCurrentTime() {
        const now = new Date()
        return `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
        clearInterval(this.timer)
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})